package com.bjfu.gmms.servlet;

import com.bjfu.gmms.MyBatisUtil;
import com.bjfu.gmms.mapper.MentorMapper;
import com.bjfu.gmms.model.Mentor;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/mentorInfoQueryServlet")
public class MentorInfoQueryServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try(SqlSession sqlSession = MyBatisUtil.getSqlSession("development")){
            // 查询所有的导师身份
            MentorMapper mentorMapper = sqlSession.getMapper(MentorMapper.class);
            List<Mentor> mentors = mentorMapper.getAllMentors();
            request.setAttribute("mentors", mentors);
            for (Mentor mentor : mentors) {
                System.out.println(mentor);
            }
            // 转发到 JSP 页面进行展示
            request.getRequestDispatcher("/mentorsShow/dashboard.jsp").forward(request, response);
        }
    }
}
